#define _CRT_SECURE_NO_WARNINGS 1

//#include<stdio.h>
//
//int containsDuplicate(int* nums, int numsSize) {
//    int* cur1 = nums;
//    for (int i = 0; i < numsSize - 1; i++)
//    {
//        int* tmp = cur1 + 1;
//        for (int j = 0; j<numsSize-i; j++)
//        {
//            if (*cur1 == *tmp)
//            {
//                return 1;
//            }
//            tmp++;
//        }
//        cur1++;
//    }
//    return 0;
//}
//
//int main()
//{
//    int arr[] = { 2,14,18,22,22 };
//    printf("%d\n", containsDuplicate(arr,5));
//
//    return 0;
//}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int toInt(char* arr)
{
    int flag = 1;
    char* cur = arr;
    if (*cur == '-')
    {
        flag = -1;
        cur++;
    }
    if (*cur == '+')
    {
        cur++;
    }
    int ret = 0;
    while (*cur != '\0')
    {
        ret = ret * 10 + (*cur - '0');
        cur++;
    }
    return ret*flag;
}

int evalRPN(char** tokens, int tokensSize) {
    int* arr = (int*)malloc(tokensSize * sizeof(int));
    int tail = 0;
    for (int i = 0; i < tokensSize; i++)
    {
        if (strcmp(tokens[i], "+") == 0 || strcmp(tokens[i], "-") == 0
            || strcmp(tokens[i], "*") == 0 || strcmp(tokens[i], "/") == 0)
        {
            int num2 = arr[--tail];
            int num1 = arr[--tail];
            switch (tokens[i][0])
            {
            case '+':
                arr[tail++] = num1 + num2;
                break;
            case '-':
                arr[tail++] = num1 - num2;
                break;
            case '*':
                arr[tail++] = num1 * num2;
                break;
            case '/':
                arr[tail++] = num1 / num2;
                break;
            }
        }
        else
        {
            int ret = toInt(tokens[i]);
            arr[tail++] = ret;
        }
    }
    return arr[tail-1];
}

int main()
{
    char* arr[] = { "4","13","5","/","+" };
    int ret = evalRPN(arr, 5);
    printf("%d\n", ret);

    return 0;
}